<template>
	<div style="padding:0 20px;">
		<a-space :size="0" style="padding:15px 15px; border: 1px solid #e2e7f0;border-left: 4px solid #3760f3">
			<div
				style="border-radius:10px ;background-color: #2f54eb;color: white;font-size: x-large; padding:5px 3px 5px 13px; width: 50px;height: 50px">
				络
			</div>
			<a-row style="margin-top: 8px">
				<a-col :span="6">
					<a-space direction="vertical" style="margin-left: 20px">
						<div>
							<span style="font-size: larger;font-weight: bold">
								{{ topDataObj.workingProcedure_dictText }}
								<a-tag style="margin-left: 10px" color="blue">
									{{ topDataObj.shift_dictText }}
								</a-tag>
							</span>
						</div>
						<div style="width: 350px">
							<span> 排班编号：{{ topDataObj.schedulingNo }} </span>
						</div>
						<div style="width: 350px">
							<span> 开始时间：{{ topDataObj.startTime }} </span>
						</div>
					</a-space>
				</a-col>
				<a-col :span="6">
					<a-space direction="vertical" style="margin-left: 20px">
						<div style="width: 350px">
							<span> 公司：{{ topDataObj.company_dictText }} </span>
						</div>
						<div style="width: 350px">
							<span> 车间：{{ topDataObj.workshop_dictText }} </span>
						</div>
						<div style="width: 350px">
							<span> 结束时间：{{ topDataObj.endTime }} </span>
						</div>
					</a-space>
				</a-col>
				<a-col :span="6">
					<a-space direction="vertical" style="margin-left: 20px">
						<div style="width: 350px">
							<span> 时间：{{ topDataObj.planTime }} </span>
						</div>
						<div style="width: 350px">
							<span> 班制：{{ topDataObj.shiftType_dictText }} </span>
						</div>
					</a-space>
				</a-col>
				<a-col :span="6">
					<a-space direction="vertical" style="margin-left: 20px">
						<div style="width: 350px">
							<span> 班长：{{ topDataObj.monitor_dictText }} </span>
						</div>
						<div style="width: 350px">
							<span> 班教：{{ topDataObj.coach_dictText }} </span>
						</div>
					</a-space>
				</a-col>
			</a-row>
			<div>
				<a-date-picker v-model="queryParam.paiBanTime" :format="dateFormat" @change="timeChange" />
			</div>
		</a-space>

		<div>
			<div style="display: inline-flex;margin-top: 20px;font-size: large">
				班次人员
			</div>

			<a-button @click="batchDel"
				style="display: inline-flex;padding: 5px;background-color: white;color: #fa3e3e;border: 1px solid #fa3e3e;border-radius: 5px;margin-left: 10px;">
				一键删除
			</a-button>
			<a-space style="float: right;margin-top: 20px">
				<a-button @click="handleSearch()" type="primary">查询</a-button>
				<a-button @click="handleAddCheck()" type="primary">添加人员</a-button>
				<a-button icon="plus-circle" @click="copyYesterdayPlan">复制昨日排班</a-button>
				<a-button>导出排班表</a-button>
			</a-space>
		</div>
		<div
			style="background: #ffffff; border-radius: 5px; padding: 20px; padding-bottom: 100px; position: relative;margin-top: 20px">
			<a-table :scroll="{ x: true, y: true }"
				:rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" :columns="columns"
				:dataSource="dataSource" rowKey="id" :loading="loading" :pagination="false">
				<div slot="工种" slot-scope="text, record">
					<a-space>
						<j-dict-select-tag placeholder="请选择工种" v-model="text" dictCode="work_type"
							@change="selectChange(text, 'workType', record)" />
					</a-space>
				</div>

				<div slot="realname" slot-scope="text, record, index, column">
					<div :style="record.scheduled ? 'color:red' : ''">
						{{record.scheduled ? text+'-多工序排班' : text}}
					</div>
				</div>

				<template v-for="(item, itemIndex) in [
						{ name: 'cscs1', aaa: '222' },
						{ name: '测试1', aaa: '333' }
					  ]">
					<a-table-column :title="item.name" :key="item.aaa" :width="100">
						<template slot-scope="text, record">
							{{ 123 }}
						</template>
					</a-table-column>
				</template>
				<!--        v-for="(item,index) in record.schedulingSpoolingDevices" :key="index"-->
				<div slot="动态列" slot-scope="text, record, index, column">
					<a-space>
						<div v-html="text"></div>
						<a-button v-if="text != ''" type="primary" ghost size="small" icon="plus"
							@click="showModal(record, '络筒', column)"></a-button>
					</a-space>
				</div>
				<div slot="锭数" slot-scope="text, record">
					<a-space>
						<!-- <div v-html="findRanges(record['ingotsIds'])"></div> -->
						<div>{{ concatIngotsIds(record.schedulingSpoolingDevices) }}</div>
						<a-button v-if="record.schedulingSpoolingDevices.length > 0" type="primary" ghost size="small"
							icon="plus" @click="showDingModalTotal(record)"></a-button>
					</a-space>
				</div>
				<div slot="开始时间" slot-scope="text, record">
					<a-space>
						<a-date-picker format="HH:mm:ss" show-time v-model="text" style="width: 100%;"
							placeholder="选择日期" :allowClear="false" mode='time'
							@change="selectChange(text, 'startTime', record)" />
					</a-space>
				</div>
				<div slot="结束时间" slot-scope="text, record">
					<a-space>
						<a-date-picker format="HH:mm:ss" mode='time' show-time v-model="text" style="width: 100%;"
							placeholder="选择日期" :allowClear="false" @change="selectChange(text, 'endTime', record)" />
					</a-space>
				</div>
				<div slot="考勤状态" slot-scope="text, record">
					<a-space>
						<j-dict-select-tag placeholder="请选择考勤状态" v-model="text" dictCode="attendance_status"
							@change="selectChange(text, 'attendanceStatus', record)" />
					</a-space>
				</div>
				<!-- 操作 -->
				<a-space slot="action" slot-scope="text, record">
					<template>
						<a-popconfirm title="确认要移除吗?" ok-text="是" cancel-text="否" @confirm="handleDelete(record.id)">
							<a-button style="color: red;padding: 0px" type="link" icon="delete">删除</a-button>
						</a-popconfirm>
					</template>
				</a-space>
			</a-table>
			<a-pagination style="position: absolute; bottom: 10px" :default-current="ipagination.current"
				:total="ipagination.total" @change="onChangePage" />
			<span style="position: absolute; bottom: 10px; right: 20px">{{ ipagination.total }}结果</span>
		</div>
		<!-- 表单区域 -->
		<luotong-user-modal ref="modalForm" @ok="modalFormOk" :selectQuery="selectQuery" :planTime="queryParam.planTime"
			:shiftSecList="shiftSecList"></luotong-user-modal>
		<!-- <jitai-luotong-modal ref="jitaiLuotongModal" @editSubmit="editSubmit"></jitai-luotong-modal> -->
		<jitai-modal ref="luotongModal" @editSubmit="editSubmit"></jitai-modal>
		<dingshu-modal ref="dingshuModal" @btnSure="btnSure"></dingshu-modal>
		<!-- 锭数编辑总表单 -->
		<a-modal title="锭数编辑总表单" :width="400" :visible="visibleDingTotal" :confirmLoading="confirmLoading"
			@ok="handleOk" @cancel="handleCancel" cancelText="关闭">
			<a-row v-for="(item, index) in editData.schedulingSpoolingDevices" :key="index" :gutter="16">
				<a-col :span="10">
					<!-- <div style="text-align: center; font-weight: bold; align-items: center; display: flex;"> -->
					<a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol">
						<span style="font-weight: bold; margin-left: 10%">
							{{ item.devices[0].deviceNo + '号机' }}
						</span>
					</a-form-model-item>
				</a-col>
				<a-col :span="12">
					<a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="锭数">
						<a-space>
							<a-input placeholder="请选择" style="width:100%" readOnly
								v-model="item.ingotsIdsTxt"></a-input>
							<a-button type="primary" icon="plus" size="small"
								@click="showDingModal(item.ingotsIds, index)"></a-button>
						</a-space>
					</a-form-model-item>
				</a-col>
			</a-row>
		</a-modal>
		<a-modal title="请选择开始结束时间" :visible="attendanceVisible" @ok="handleltOk" @cancel="attendanceVisible = false">
			开始时间：<a-date-picker show-time v-model="startTime" style="width: 100%; margin-bottom: 20px;"
				placeholder="申请开始时间" :allowClear="false" />

			结束时间：<a-date-picker show-time v-model="endTime" style="width: 100%;" placeholder="申请结束时间"
				:allowClear="false" />
		</a-modal>
	</div>
</template>

<script>
	import _ from 'lodash'
	import {
		httpAction
	} from '@/api/manage'
	import JitaiModal from './modules/JitaiModal'
	const path = '/crm_scheduling_spooling/crmSchedulingSpooling'
	import moment from 'moment'
	import {
		JeecgListMixin
	} from '@/mixins/JeecgListMixin'
	import LuotongUserModal from '@views/productionDispatchManagement/schedulingManagement/modules/LuotongUserModal.vue'
	import {
		copyYesterdayDailyPlanNew,
		editDeviceSpooling,
		editSchedulingPreSpin,
		getDailyPlanSpunYarn,
		getDailyPlanSpooling,
		getShiftSec,
		editSchedulingSpooling
	} from '../../../api/customApi'
	import Luotong from '../../SystemManage/Quota/luotong'
	import DingshuModal from './modules/DingshuModal'
	import JitaiLuotongModal from './modules/JitaiLuotongModal'

	export default {
		name: 'Luotong',
		inject: ['selectQuery'],
		mixins: [JeecgListMixin],
		components: {
			JitaiLuotongModal,
			Luotong,
			LuotongUserModal,
			DingshuModal
		},
		data() {
			return {
				labelCol: {
					xs: {
						span: 24
					},
					sm: {
						span: 6
					}
				},
				wrapperCol: {
					xs: {
						span: 24
					},
					sm: {
						span: 18
					}
				},
				visibleDingTotal: false, //锭数编辑弹窗
				editData: {},
				confirmLoading: false,
				shiftSecList: [],
				topDataObj: {
					workingProcedure_dictText: '',
					shift_dictText: '',
					schedulingNo: '',
					company_dictText: '',
					workshop_dictText: '',
					planTime: '',
					shiftType_dictText: '',
					monitor_dictText: '',
					coach_dictText: '',
					company: '',
					workshop: '',
					shift: '',
				},
				isShift: false,
				dateFormat: 'YYYY-MM-DD',
				columns: [],
				queryParam: {
					paiBanTime: moment().format('YYYY-MM-DD'),
					planTime: moment().format('YYYY-MM-DD'),
					company: '1771136798305476610',
					workshop: 5,
					shift: 1
				},
				showList: [],
				url: {
					list: path + '/list',
					delete: path + '/delete',
					deleteBatch: path + '/deleteBatch',
					toDetail: '/personnelInformation/modules/blacklistDetails',
					edit: '/crm_scheduling_spooling/crmSchedulingSpooling/edit'
				},
				defaultColumns: [],
				attendanceVisible: false,
				startTime: '',
				endTime: '',
				record: '',
				attendanceType: ''
			}
		},
		watch: {
			dataSource(newVal) {
				this.generateDynamicColumns(newVal)
			}
		},
		mounted() {
			this.selectShiftSec()
		},

		methods: {
			// dayTimechange(time){
			// 	console.log(time,'??????')
			// 	var arr = time.split(' ')
			// 	console.log(arr,'arr？？？？？？')
			// 	return monent(arr[1],'HH:mm:ss')
			// },
			selectShiftSec() {
				let query = {
					company: this.selectQuery.company,
					shift: this.selectQuery.shift,
					workshop: this.selectQuery.workshop,
					planTime: this.queryParam.paiBanTime,
					workingProcedure: '7'
				}
				console.log(this.selectQuery.workshop + 'aaaaaaaaaaaaawwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww')
				getShiftSec(query).then(res => {
					if (res.success) {
						if (res.result.records.length > 0) {
							this.shiftSecList = res.result.records
							this.topDataObj = res.result.records[0]
							this.isShift = true
							this.$message.success('查询成功')
						} else {
							this.topDataObj = {
								workingProcedure_dictText: '',
								shift_dictText: '',
								schedulingNo: '',
								company_dictText: '',
								workshop_dictText: '',
								planTime: '',
								shiftType_dictText: '',
								monitor_dictText: '',
								coach_dictText: '',
								company: '',
								workshop: '',
								shift: '',
							}
							this.isShift = false
							this.$message.warning('没有查询到轮班信息，请去轮班管理安排当日班次')
						}
					} else {
						this.$message.warning(res.message)
					}
					// this.searchQuery()
				})
			},
			timeChange(date, dateString) {
				this.queryParam.planTime = dateString
				this.queryParam.paiBanTime = dateString
				this.handleSearch()
				// this.selectShiftSec();
			},
			handleSearch: _.debounce(function() {
				this.queryParam.company = this.selectQuery.company
				this.queryParam.workshop = this.selectQuery.workshop
				this.queryParam.shift = this.selectQuery.shift
				this.selectShiftSec()
				this.loadData()
			}, 500), //0.5s防抖
			copyYesterdayPlan() {
				let query = {
					planTime: this.queryParam.paiBanTime,
					company: this.topDataObj.company,
					workingProcedure: '7',
					workshop: this.topDataObj.workshop,
					shift: this.topDataObj.shift,
				}
				copyYesterdayDailyPlanNew(query).then(res => {
					if (res.success) {
						this.$message.success('复制成功')
					}
					this.loadData()
				})
			},
			generateDynamicColumns(dataSource) {
				this.columns = [{
						title: '姓名',
						align: 'center',
						dataIndex: 'realname',
						ellipsis: true,
						scopedSlots: {
							customRender: 'realname'
						},
						width: 150
					},
					{
						title: '工号',
						align: 'center',
						dataIndex: 'workNo',
						ellipsis: true,
						width: 150
					},
					{
						title: '工种',
						align: 'center',
						dataIndex: 'workType',
						ellipsis: true,
						scopedSlots: {
							customRender: '工种'
						},
						width: 150
					},
					// {
					//   title: '工序',
					//   align: 'center',
					//   dataIndex: 'workingProcedure_dictText',
					//   ellipsis: true,
					//   width: 150
					// },
					{
						title: '设备总台数',
						align: 'center',
						dataIndex: 'deviceNum',
						ellipsis: true,
						width: 100
					},
					{
						title: '看台定额测算',
						align: 'center',
						dataIndex: 'calculation',
						ellipsis: true,
						width: 100
					},
					{
						title: '锭数',
						align: 'center',
						dataIndex: 'ingotsIds',
						ellipsis: true,
						scopedSlots: {
							customRender: '锭数'
						},
						width: 200
					},
					{
						title: '开始时间',
						align: 'center',
						dataIndex: 'startTime',
						scopedSlots: {
							customRender: '开始时间'
						},
						width: 220,
						ellipsis: true
					},
					{
						title: '结束时间',
						align: 'center',
						dataIndex: 'endTime',
						scopedSlots: {
							customRender: '结束时间'
						},
						width: 220,
						ellipsis: true
					},
					{
						title: '考勤状态',
						align: 'center',
						dataIndex: 'attendanceStatus',
						ellipsis: true,
						scopedSlots: {
							customRender: '考勤状态'
						}
					},
					// {
					// 	title: '请假开始时间',
					// 	align: 'center',
					// 	dataIndex: 'leaveStartTime',
					// 	width: 220,
					// 	scopedSlots: {
					// 		customRender: '请假开始时间'
					// 	},
					// 	ellipsis: true
					// },
					// {
					// 	title: '请假结束时间',
					// 	align: 'center',
					// 	dataIndex: 'leaveEndTime',
					// 	width: 220,
					// 	scopedSlots: {
					// 		customRender: '请假结束时间'
					// 	},
					// 	ellipsis: true
					// },
					// {
					// 	title: '缺勤开始时间',
					// 	align: 'center',
					// 	dataIndex: 'absentStartTime',
					// 	width: 220,
					// 	scopedSlots: {
					// 		customRender: '缺勤开始时间'
					// 	},
					// 	ellipsis: true
					// },
					// {
					// 	title: '缺勤结束时间',
					// 	align: 'center',
					// 	dataIndex: 'absentEndTime',
					// 	width: 220,
					// 	scopedSlots: {
					// 		customRender: '缺勤结束时间'
					// 	},
					// 	ellipsis: true
					// },
					{
						title: '备注',
						align: 'center',
						dataIndex: 'remark',
						ellipsis: true
					},
					{
						title: '操作',
						dataIndex: 'action',
						align: 'center',
						scopedSlots: {
							customRender: 'action'
						},
						fixed: 'right'
					}
				]
				let trendsColumn = []
				let query = {
					planTime: this.queryParam.paiBanTime,
					workshop: this.selectQuery.workshop
				}
				getDailyPlanSpooling(query).then(res => {
					console.log('soop;ongresres', res)
					this.showList = []
					if (res.success) {
						this.showList = res.result.records
						this.showList.forEach(item => {
							trendsColumn.push({
								title: item.productType_dictText,
								align: 'center',
								dataIndex: item.id,
								ellipsis: true,
								width: 250,
								scopedSlots: {
									customRender: '动态列'
								}
							})
							//修改数据格式
							dataSource.forEach(i => {
								let trendsValue = ''
								i.schedulingSpoolingDevices.forEach(sly => {
									if (item.id == sly.dailyPlanId) {
										sly.devices.forEach(device => {
											trendsValue += device
												.workshopDictText + '-' + device
												.deviceNo + ';'
										})
									}
								})
								if (trendsValue != '') {
									i[item.id] = this.parseAndFormat(trendsValue)
								}
							})
						})

						const indexToInsert = this.columns.findIndex(col => col.dataIndex ===
							'workingProcedure_dictText')
						this.columns.splice(3, 0, ...trendsColumn) // 在工序列后面插入动态生成的列头
					} else {
						that.$message.warning(res.message)
					}
				})
			},
			parseAndFormat(input) {
				// 移除结尾的分号（如果有）
				input = input.replace(/;$/, '')

				// 解析输入字符串，按“;”分隔
				let entries = input.split(';')

				// 存储结果的对象
				let workshopGroups = {}

				// 遍历每个条目
				entries.forEach(entry => {
					let [workshop, number] = entry.split('-')
					number = parseInt(number, 10)

					if (!workshopGroups[workshop]) {
						workshopGroups[workshop] = []
					}
					workshopGroups[workshop].push(number)
				})

				// 结果字符串
				let result = []

				// 处理每个车间的编号
				for (let workshop in workshopGroups) {
					let numbers = workshopGroups[workshop]
					numbers.sort((a, b) => a - b)

					let ranges = []
					let rangeStart = numbers[0]
					let rangeEnd = numbers[0]

					for (let i = 1; i < numbers.length; i++) {
						if (numbers[i] === rangeEnd + 1) {
							rangeEnd = numbers[i]
						} else {
							if (rangeStart === rangeEnd) {
								ranges.push(`#${rangeStart}`)
							} else {
								ranges.push(`#${rangeStart}~#${rangeEnd}`)
							}
							rangeStart = numbers[i]
							rangeEnd = numbers[i]
						}
					}

					if (rangeStart === rangeEnd) {
						ranges.push(`#${rangeStart}`)
					} else {
						ranges.push(`#${rangeStart}~#${rangeEnd}`)
					}

					result.push(`${workshop}：${ranges.join('；')}`)
				}

				return result.join('<br>')
			},
			moment,
			findRanges(numbersStr) {
				let numbers = numbersStr.split(',').map(Number) // 将字符串转换为数字数组
				numbers = Array.from(new Set(numbers)).sort((a, b) => a - b) // 去重并排序

				let fullRange = Array.from({
					length: 64
				}, (_, i) => i + 1) // 完整的1到64的范围
				let missingNumbers = fullRange.filter(num => !numbers.includes(num)) // 找到缺失的数字

				if (missingNumbers.length === 0) {
					return '1~64'
				}

				let ranges = []
				let start = 1

				missingNumbers.forEach(missing => {
					if (start < missing) {
						let end = missing - 1
						ranges.push(`${start}~${end}`)
					}
					start = missing + 1
				})

				if (start <= 64) {
					ranges.push(`${start}~64`)
				}

				return ranges.join('；')
			},
			concatIngotsIds(arr) {
				// 锭数非空
				if (arr != []) {
					// 先根据机台号排序
					let sortedArr = arr
						.map(item => item)
						.sort(
							(a, b) =>
							(a.deviceNo ? a.deviceNo : a.devices[0].deviceNo) - (b.deviceNo ? b.deviceNo : b.devices[0]
								.deviceNo)
						)
					let map = {}
					sortedArr.forEach(obj => {
						if (map[obj.ingotsIds]) {
							map[obj.ingotsIds].push(obj.devices[0].deviceNo)
						} else {
							map[obj.ingotsIds] = [obj.devices[0].deviceNo]
						}
					})

					let result = []
					for (let key in map) {
						result.push(map[key].join(', ') + ': #' + this.findRanges(key))
					}

					return result.join('，')
				}
				//如果锭数为空
				else {
					return ''
				}
			},
			onChangePage(e) {
				this.ipagination.current = e
				this.loadData()
			},
			showModal(records, param, column) {
				records.planId = column.key
				this.$refs.jitaiLuotongModal.show(records, param, false)
			},
			selectChange(value, label, record) {
				console.log(value)
				console.log(label)

				if (label == 'attendanceStatus') {
					if (value == '4' || value == '5') {
						this.attendanceVisible = true
						this.startTime = record.startTime
						this.endTime = record.endTime
						this.record = record
						this.attendanceType = value
						return
					}
				}
				let query = {
					id: record.id,
					workType: label == 'workType' ? value : record.workType,
					attendanceStatus: label == 'attendanceStatus' ? value : record.attendanceStatus,
					startTime: label == 'startTime' ? moment(value).format('YYYY-MM-DD') + ' 00:00:00' : null,
					endTime: label == 'endTime' ? moment(value).format('YYYY-MM-DD') + ' 12:00:00' : null
				}
				editSchedulingSpooling(query).then(res => {
					if (res.success) {
						this.$message.success('修改成功')
					}
					this.loadData()
				})
			},
			editSubmit(params, selectPlanData, chose, row) {
				console.log('触发了editSubmit')
				console.log('editSubmit-choseNum', chose)
				console.log('editSubmit-row', row)
				// 暂存用的数组
				let cacheArr = []
				// 赋值用新数组
				let newArr = []
				let mapA = {} //原数组键值对
				let mapB = {} //新数组键值对
				for (let i = 0; i < chose.length; i++) {
					cacheArr.push({
						dailyPlanId: chose[i].split('*')[0],
						deviceIds: chose[i].split('*')[1],
						ingotsIds: '1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64',
						ingotsIdsTxt: this.findRanges(
							'1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64'
						),
						deviceNo: chose[i].split('*')[2]
					})
				}
				// 将数组 A 中的对象以 dailyPlanId 和 deviceIds 为键存入 mapA
				row.schedulingSpoolingDevices.forEach(obj => {
					mapA[obj.dailyPlanId + obj.deviceIds] = obj
				})
				// 将数组 B 中的对象以 dailyPlanId 和 deviceIds 为键存入 mapB
				cacheArr.forEach(obj => {
					mapB[obj.dailyPlanId + obj.deviceIds] = obj
				})
				// 遍历数组 A，如果数组 B 中有对应的对象，则加入新数组 C
				row.schedulingSpoolingDevices.forEach(obj => {
					if (mapB[obj.dailyPlanId + obj.deviceIds]) {
						newArr.push(obj)
					}
				})
				// 遍历数组 B，如果数组 A 中没有对应的对象，则加入新数组 C
				cacheArr.forEach(obj => {
					if (!mapA[obj.dailyPlanId + obj.deviceIds]) {
						newArr.push(obj)
					}
				})
				console.log('newarr', newArr)
				let formData = row
				formData.schedulingSpoolingDevices = newArr
				//选择的机台id
				// selectPlanData.forEach(item => {
				//   item.deviceIds = item.deviceIds.join(',')
				// })
				// console.log(selectPlanData)
				// let query = {
				//   id: row.id,
				//   schedulingSpoolingDevices: selectPlanData
				// }
				editSchedulingSpooling(formData).then(res => {
					if (res.success) {
						this.$message.success('修改成功')
						this.loadData()
					} else {
						this.$message.error(res.message)
					}
				})
			},
			// 判断是否有轮班信息，没有的话无法打开添加人员
			handleAddCheck() {
				if (this.isShift == true) {
					this.handleAdd()
				} else {
					this.$message.warning('没有查询到轮班信息，请去轮班管理安排当日班次')
				}
			},
			showDingModal(ingotsIds, index) {
				// this.$refs.dingshuModal.show(text, '', false, false, record)
				this.$refs.dingshuModal.show(ingotsIds, '', index, true)
			},
			btnSure(selectIds, selectString, index) {
				console.log('selectString', selectString)
				console.log('ingotsIds', this.editData.schedulingSpoolingDevices[index])
				this.editData.schedulingSpoolingDevices[index].ingotsIds = selectString
				this.editData.schedulingSpoolingDevices[index].ingotsIdsTxt = this.findRanges(selectString)
				// this.searchQuery()
			},
			showDingModalTotal(record) {
				this.visibleDingTotal = true
				this.editData = record
				this.editData.schedulingSpoolingDevices.forEach(item => {
					item.ingotsIdsTxt = this.findRanges(item.ingotsIds)
				})
				console.log('this.editData', this.editData)
			},
			handleltOk() {
				if (this.attendanceType == '4') {
					var query = {
						id: this.record.id,
						attendanceStatus: this.attendanceType,
						absentStartTime: moment(this.startTime).format('YYYY-MM-DD') + ' 00:00:00',
						absentEndTime: moment(this.endTime).format('YYYY-MM-DD') + ' 12:00:00'
					}
				} else {
					var query = {
						id: this.record.id,
						attendanceStatus: this.attendanceType,
						leaveStartTime: moment(this.startTime).format('YYYY-MM-DD') + ' 00:00:00',
						leaveEndTime: moment(this.endTime).format('YYYY-MM-DD') + ' 12:00:00'
					}
				}
				editSchedulingSpooling(query).then(res => {
					this.attendanceVisible = false
					if (res.success) {
						this.$message.success('修改成功')
					}
					this.loadData()
				})
			},
			// 编辑锭数
			handleOk() {
				this.confirmLoading = true
				let httpurl = ''
				let method = ''
				httpurl += this.url.edit
				method = 'put'
				let formData = Object.assign(this.editData)
				httpAction(httpurl, formData, method)
					.then(res => {
						if (res.success) {
							this.$message.success(res.message != '' ? res.message : '执行成功')
							this.$emit('ok')
						} else {
							this.$message.warning(res.message)
						}
					})
					.finally(() => {
						this.confirmLoading = false
						this.visibleDingTotal = false
					})
			},
			handleCancel() {
				this.visibleDingTotal = false
			}
		}
	}
</script>

<style></style>